package io.ent.modules.product.controller;

import java.util.Arrays;
import java.util.Map;

import io.ent.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.ent.modules.product.entity.ProductCasePicsEntity;
import io.ent.modules.product.service.ProductCasePicsService;
import io.ent.common.utils.PageUtils;
import io.ent.common.utils.R;



/**
 * 
 *
 * @author Mark
 * @email sunlightcs@gmail.com
 * @date 2019-10-14 15:50:16
 */
@RestController
@RequestMapping("product/productcasepics")
public class ProductCasePicsController {
    @Autowired
    private ProductCasePicsService productCasePicsService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("product:productcasepics:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = productCasePicsService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("product:productcasepics:info")
    public R info(@PathVariable("id") Integer id){
        ProductCasePicsEntity productCasePics = productCasePicsService.getById(id);

        return R.ok().put("productCasePics", productCasePics);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("product:productcasepics:save")
    public R save(@RequestBody ProductCasePicsEntity productCasePics){
        productCasePicsService.save(productCasePics);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("product:productcasepics:update")
    public R update(@RequestBody ProductCasePicsEntity productCasePics){
        ValidatorUtils.validateEntity(productCasePics);
        productCasePicsService.updateById(productCasePics);
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("product:productcasepics:delete")
    public R delete(@RequestBody Integer[] ids){
        productCasePicsService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }
    /**
     * 删除
     */
    @RequestMapping("/updatePicIsDelById")
    public R updatePicIsDelById(@RequestBody Integer[] ids){
        if (productCasePicsService.updatePicIsDelById(ids[0])){
            return R.ok("修改成功");
        }else {
            return R.error("修改失败");
        }
    }

}
